package design_patterns;

/**
 * 单例模式（懒汉、恶汉）
 *
 * @author yujiafan
 * @version 1.0.0
 * @create 2022-05-26
 */
public class Singleton {

    private static Singleton instance;

    private Singleton(){
    }

    public static synchronized Singleton getInstance(){
        if(instance == null){
            instance = new Singleton();
        }
        return instance;
    }

}
class Singleton1 {
    private static Singleton1 instance = new Singleton1();

    private Singleton1(){
    }

    public static Singleton1 getInstance(){
        return instance;
    }
}
